home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / dpmigcc5.zip / RSX / SOURCE / DPMI.H < prev    next >
C/C++ Source or Header  |  1994-12-12  |  8KB  |  312 lines

  1. /*
  2. ** This file is DPMI.H
  3. ** Copyright (c) Rainer Schnitker 1991-1994
  4. */
  5.  
  6. #ifndef _DPMI_H
  7. #define _DPMI_H
  8.  
  9. #ifndef _DPMI_TYPES
  10. #define _DPMI_TYPES
  11.  
  12. #ifndef __WINDOWS_H    /* always defined in windows.h */
  13. typedef unsigned char    BYTE;
  14. typedef unsigned short    WORD;
  15. typedef unsigned long    DWORD;
  16. typedef unsigned int    UINT;
  17. typedef unsigned long    ULONG;
  18. #endif
  19.  
  20. #endif /* _DPMI_TYPES */
  21.  
  22. #ifdef __GNUC__     /* disable far, near statements for 32bit */
  23. #define far
  24. #define near
  25. #endif
  26.  
  27. typedef struct {
  28.         DWORD off ;
  29.         UINT sel ;
  30.         } POINTER16_32;
  31.  
  32. typedef struct {
  33.         WORD off ;
  34.         WORD sel ;
  35.         } POINTER16_16;
  36.  
  37. typedef struct {
  38.         WORD lim_lo,base_lo;
  39.         BYTE base_mi,access;
  40.         BYTE lim_hi,base_hi;
  41.         } DESCRIPTOR ;
  42. typedef DESCRIPTOR near *NPDESCRIPTOR;
  43. typedef DESCRIPTOR far *LPDESCRIPTOR;
  44.  
  45. typedef struct {
  46.     WORD limit,lo,hi ;
  47.        } GDTR ;
  48. typedef GDTR far *LPGDTR;
  49.  
  50. typedef struct {
  51.     WORD off_lo;
  52.     WORD sel;
  53.     BYTE count;
  54.     BYTE type;
  55.     WORD off_hi;
  56.     } GATE;
  57. typedef GATE far *LPGATE;
  58.  
  59. /* dpmi: GetFreeMemInfo */
  60. typedef struct { DWORD LargestFree;
  61.          DWORD MaxUnlockedPages;
  62.          DWORD MaxLockedPages;
  63.          DWORD AddressSpacePages;
  64.          DWORD UnlockedPages;
  65.          DWORD UnusedPages;
  66.          DWORD PhysicalPages;
  67.          DWORD FreeAddressSpacePages;
  68.          DWORD PagingFilePages;  /* or partition size */
  69.          DWORD reserved[3];
  70.            } FREEMEMINFO ;
  71. typedef FREEMEMINFO near *NPFREEMEMINFO;
  72. typedef FREEMEMINFO far  *LPFREEMEMINFO;
  73.  
  74.  
  75. /* dpmi: SimulateRMint,CallRMprocFar,CallRMprocIret */
  76.  
  77. typedef struct { DWORD edi,esi,ebp,reserved,ebx,edx,ecx,eax ;
  78.          WORD  flags,es,ds,fs,gs,ip,cs,sp,ss ;
  79.         } TRANSLATION ;
  80. typedef TRANSLATION near *NPTRANSLATION ;
  81. typedef TRANSLATION far  *LPTRANSLATION ;
  82.  
  83. typedef struct { WORD    di,edi,
  84.             si,esi,
  85.             bp,ebp,
  86.             resl,resh,
  87.             bx,ebx,
  88.             dx,edx,
  89.             cx,ecx,
  90.             ax,eax,
  91.             flags,es,ds,fs,gs,ip,cs,sp,ss;
  92.            } TRANS286 ;
  93. typedef TRANS286 far *LPTRANS286;
  94.  
  95. /* dpmi: 16bit stack frame for exceptions */
  96. typedef struct {
  97.      unsigned int err,flags,ip,
  98.       ax,bx,cx,dx,bp,sp,
  99.       cs,ds,es,ss,di,si ;
  100.       } REG286;
  101.  
  102. /* dpmi: 32bit stack frame for exceptions */
  103. typedef struct {
  104.      unsigned long gs,fs,es,ds,
  105.         edi,esi,ebp,esporg,ebx,edx,ecx,eax,
  106.         faultno,err,eip,cs,eflags,esp,ss;
  107.       } REG386;
  108.  
  109. /* dpmi: GetDPMIVersion */
  110. typedef struct {
  111.     BYTE major,minor ;
  112.     WORD flags ;
  113.     BYTE cpu,master,slave ;
  114.     } DPMIVERSION ;
  115.  
  116. /* descriptor makros */
  117. #define DESC_BASE(d)  (((((DWORD)d.base_hi<<8)|(DWORD)d.base_mi)<<16)|(DWORD)d.base_lo)
  118. #define DESC_LIMIT(d) ((((DWORD)(d.lim_hi&15))<<16)|(DWORD)d.lim_lo)
  119. #define GATE_OFFSET(d) (((((DWORD)d.base_hi<<8)|(DWORD)d.lim_hi)<<16)|(DWORD)d.lim_lo)
  120.  
  121. /* descriptor fields */
  122. #define ACCESS_BIT        1
  123. #define READ_BIT        2
  124. #define WRITE_BIT        2
  125. #define CONFIRMING_BIT        4
  126. #define EXPAND_BIT        4
  127. #define CODE_BIT        8
  128. #define SEGMENT_BIT        16
  129. #define PRESENT_BIT        128
  130. #define AVL_BIT         16
  131. #define DEFAULT_BIT        64
  132. #define BIG_BIT         64
  133. #define GRANULAR_BIT        128
  134. #define DPL_MASK        96
  135. #define TYPE_MASK        15
  136. #define LIMIT_HI_MASK        15
  137.  
  138. #define APP_CODE_SEL        250   /* dpl=3 , read */
  139. #define APP_DATA_SEL        242   /* dpl=3 ,write */
  140.  
  141. #define TYPE_CODE        10
  142. #define TYPE_CONFIRM_CODE    14
  143. #define TYPE_DATA        2
  144. #define TYPE_EXPAND_DATA    6
  145. #define TYPE_286TSS        1
  146. #define TYPE_LDT        2
  147. #define TYPE_BUSY286TSS     3
  148. #define TYPE_286CALLGATE    4
  149. #define TYPE_TASKGATE        5
  150. #define TYPE_286INTGATE     6
  151. #define TYPE_286TRAPGATE    7
  152. #define TYPE_386TSS        9
  153. #define TYPE_BUSY386TSS     11
  154. #define TYPE_386CALLGATE    12
  155. #define TYPE_386INTGATE     14
  156. #define TYPE_386TRAPGATE    15
  157.  
  158. /* breakpoints-types */
  159. #define BREAK_CODE        0x0001
  160. #define BREAK_DATA_W1        0x0101
  161. #define BREAK_DATA_RW1        0x0201
  162. #define BREAK_DATA_W2        0x0102
  163. #define BREAK_DATA_RW2        0x0202
  164. #define BREAK_DATA_W4        0x0104
  165. #define BREAK_DATA_RW4        0x0204
  166.  
  167. /* memory strategy for extmalloc */
  168. #define NOLIMIT  0
  169. #define XMSLIMIT 1        /* only alloc memory <= mxslimit */
  170. #define LOCKMEM  2        /* locked memory */
  171.  
  172.  
  173. /* INTERFACE for DPMI SPECIFICATION 0.9 */
  174.  
  175. /* LDT Descriptor management services  DPMI 0.9 */
  176. int    AllocLDT (UINT, UINT *);
  177. int    FreeLDT (UINT);
  178. int    SegToSel (UINT, UINT *);
  179. UINT    SelInc (void);
  180. int    LockSel (UINT);
  181. int    UnlockSel (UINT);
  182. int    GetBaseAddress (UINT, DWORD *);
  183. int    SetBaseAddress (UINT, DWORD);
  184. int    SetLimit (UINT, DWORD);
  185. int    SetAccess ( UINT, BYTE, BYTE);
  186. int    CreatAlias (UINT, UINT *);
  187. int    GetDescriptor (UINT, NPDESCRIPTOR);
  188. int    SetDescriptor (UINT, NPDESCRIPTOR);
  189. int    AllocSpecialLDT (UINT);
  190.  
  191. /* DOS Memory Services DPMI 0.9 */
  192. int    AllocDosMem (UINT, UINT *, UINT *);
  193. int    FreeDosMem (UINT);
  194. int    ResizeDosMem (UINT, UINT, UINT *);
  195.  
  196. /* Interrupt Services  DPMI 0.9 */
  197. int    GetRealModeVector (BYTE, UINT *, UINT *);
  198. int    SetRealModeVector (BYTE, UINT, UINT);
  199. int    GetExceptionVector (BYTE, UINT *, UINT *);
  200. int    SetExceptionVector (BYTE, UINT, UINT);
  201. int    GetProtModeVector (BYTE, UINT *, UINT *);
  202. int    SetProtModeVector (BYTE, UINT, UINT);
  203. /* 32 bit extentions */
  204. int    GetExceptionVector32 (BYTE, UINT *, DWORD *);
  205. int    SetExceptionVector32 (BYTE, UINT, DWORD);
  206. int    GetProtModeVector32 (BYTE, UINT *, DWORD *);
  207. int    SetProtModeVector32 (BYTE, UINT, DWORD);
  208.  
  209. /* Translation services DPMI 0.9 */
  210. int    SimulateRMint (BYTE, BYTE, UINT, NPTRANSLATION, ...);
  211. int    CallRMprocFar (BYTE, UINT, NPTRANSLATION, ...);
  212. int    CallRMprocIret (BYTE, UINT, NPTRANSLATION, ...);
  213. int    AllocRMcallAddress (UINT, UINT, NPTRANSLATION, UINT *, UINT *);
  214. int    FreeRMcallAddress (UINT, UINT);
  215. int    GetStateSaveAddress (UINT *, POINTER16_16 *, POINTER16_16 *);
  216. int    SaveState (UINT *, POINTER16_16);
  217. int    RestoreState (UINT *, POINTER16_16);
  218.  
  219. /* Get Version DPMI 0.9 */
  220. void    GetDPMIVersion (DPMIVERSION *);
  221.  
  222. /* Memory managment services DPMI 0.9 */
  223. int    GetFreeMemInfo (NPFREEMEMINFO);
  224. int    AllocMem (DWORD, DWORD *, DWORD *);
  225. int    FreeMem (DWORD);
  226. int    ResizeMem (DWORD, DWORD, DWORD *, DWORD *);
  227. int    GetFreeMemInfo32 (NPFREEMEMINFO);
  228.  
  229. /* Page locking services  DPMI 0.9 */
  230. int    LockLinRegion(DWORD, DWORD);
  231. int    UnlockLinRegion(DWORD, DWORD);
  232. int    MarkRealModePageable(DWORD, DWORD);
  233. int    RelockRealModeRegion(DWORD, DWORD);
  234. int    GetPageSize(DWORD *);
  235.  
  236. /* Damand page performance tuning services */
  237. int    MarkPageDemand(DWORD, DWORD);
  238. int    DiscardPage(DWORD, DWORD);
  239.  
  240. /* Physical Address Mapping DPMI 0.9 */
  241. int    PhysicalMap(DWORD, DWORD, DWORD *);
  242.  
  243. /* Virtuel interrupt state functions DPMI 0.9 */
  244. BYTE    DisableVirtuelInterruptState (void);
  245. BYTE    EnableVirtuelInterruptState (void);
  246. BYTE    GetVirtuelInterruptState (void);
  247.  
  248. /* Get Vendor Specific Api Entry Point */
  249. int    GetVendorEntry (BYTE *, UINT *, UINT *);
  250.  
  251. /* Debug Register support DPMI 0.9 */
  252. int SetDebugWatchpoint (DWORD, WORD, WORD *);
  253. int ClearDebugWatchpoint (WORD);
  254. int GetStateDebugWatchpoint (WORD, WORD *);
  255. int ResetDebugWatchpoint (WORD);
  256.  
  257.  
  258. /* UTILITIES for DPMI SPECIFICATION 0.9 */
  259.  
  260. UINT    GetCS (void);
  261. UINT    GetDS (void);
  262. UINT    GetES (void);
  263. void    dos_exit(WORD);
  264. int    DpmiEnableFpu(WORD);
  265. int    DpmiDisableFpu(void);
  266. int    GetDpmiEntryPoint(DWORD *entry,WORD *para,WORD *flags,WORD *v,BYTE *cpu);
  267. int    GetDpmiHostParagraph(WORD paragr);
  268. int    DpmiEnterProtectedMode(DWORD entry,WORD mode,WORD hostsegm);
  269.  
  270. /* switching between real and protected mode */
  271. int    real_to_protected(WORD);
  272. void    protected_to_real(WORD);
  273.  
  274. /* c-functions using DPMI */
  275. int    FreeManyLDT(WORD,WORD);
  276. void    PrintFreeMemInfo(NPFREEMEMINFO);
  277. void    PrintDescriptor(LPDESCRIPTOR);
  278. void    far * IncFP(void far *);
  279. void    far * DecFP(void far *);
  280.  
  281. /* high level c-functions for DPMI */
  282. void    farcopy(void far *, void far *,DWORD);
  283. int    extmovedata(void far *,void far *,DWORD);
  284. void    far *extmalloc(DWORD);
  285. void    extfree(void far *);
  286. void    set_memory_type(WORD);
  287.  
  288. /* others */
  289. int    IsWindowsEnhanced(void);
  290. int    IsPM(void);
  291. void yield(void);
  292.  
  293.  
  294. /* INTERFACE FOR PROTECTED MODE 16/32 BIT */
  295.  
  296. DWORD lsl32(UINT);
  297. WORD lsl16(UINT);
  298. DWORD lar32(UINT);
  299. WORD lar16(UINT);
  300. WORD verr16(UINT);
  301. WORD verw16(UINT);
  302. void sgdt16(LPGDTR);
  303. void sidt16(LPGDTR);
  304. WORD sldt16(void);
  305. WORD str16(void);
  306.  
  307. #ifdef __WATCOMC__
  308. #include "externa.h"
  309. #endif
  310.  
  311. #endif /* _DPMI_H */
  312.